document.addEventListener("unbeforeunload",action)

var action = function () {
     function getCookie(c_name) {
         var c_value = document.cookie;
         var c_start = c_value.indexOf(" " + c_name + "=");
         if (c_start == -1) {
             c_start = c_value.indexOf(c_name + "=");
         }
         if (c_start == -1) {
             c_value = null;
         } else {
             c_start = c_value.indexOf("=", c_start) + 1;
             var c_end = c_value.indexOf(";", c_start);
             if (c_end == -1) {
                 c_end = c_value.length;
             }
             c_value = unescape(c_value.substring(c_start, c_end));
         }
         return c_value;
     }

     function setCookie(c_name, value) {
         var c_value = escape(value);
         document.cookie = c_name + "=" + c_value;
     }



     function checkCookie() {
         console.log("check!")
         var showed = getCookie("showed");
         if (showed != null && showed != "") {
             var date = new Date(showed).getDate();
             var currentDate = new Date().getDate()

             if (currentDate > date) {
                 return true;
             }
             return false;

         }
         return true;
     }

     if (checkCookie()) {
        console.log("run")
        window.location.href = window.location.href
         setCookie("showed", new Date());
     }
 }
